package case10;

public class Cook extends Thread{
    @Override
    public void run() {
        while (true){
            synchronized (Desk.lock){
                if (Desk.count==0){
                    break;
                }else {
                    //判断桌子上是否有食物
                    if (Desk.foodFlag==1){
                        //如果有，就等待
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else {
                        //如果没有就做
                        System.out.println("厨师做了一碗面条");
                        //改变桌子状态
                        Desk.foodFlag = 1 ;
                        //唤醒吃货开吃
                        Desk.lock.notifyAll();
                    }
                }
            }
        }
    }
}
